package top.ucat.x.file.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import top.ucat.box.cloud.common.result.Result;
import top.ucat.box.cloud.common.result.SystemResult;
import top.ucat.box.starter.oauth.common.pojo.User;
import top.ucat.box.starter.oauth.common.util.UserUtil;
import top.ucat.x.file.beans.AliOssSiguatureVo;
import top.ucat.x.file.beans.AliStsVo;
import top.ucat.x.file.beans.FileVo;
import top.ucat.x.file.service.FileService;


@RestController
@RequestMapping("/file")
@ApiIgnore
public class FileController {


    @Autowired
    private FileService fileService;

    @PostMapping("ali/sts")
    public Result getSts(@RequestParam String module) {
        User user = UserUtil.getUser();
        AliStsVo aliStsVo = fileService.getAliOssTstToken(module, user.getId());
        return SystemResult.OK.getResult(aliStsVo);
    }


    @PostMapping("ali/signature")
    public Result getSignature(@RequestParam String module) {
        User user = UserUtil.getUser();
        AliOssSiguatureVo vo = fileService.getAliOssSignature(user.getId(), module);
        return SystemResult.OK.getResult(vo);
    }

    @PostMapping("check/md5")
    public Result checkFileByMd5(@RequestParam String md5) {
        FileVo fileVo = fileService.checkFileByMd5(md5);
        return SystemResult.OK.getResult(fileVo);
    }
}
